import storage from '@/utils/storage'
const KEY_USERINFO = 'Bluer_Dai'

export let userInfoCache = (cache => {
  if (!cache) {
    return {}
  }
  try {
    return JSON.parse(cache)
  } catch (e) {
    storage.set(KEY_USERINFO, {})
    return {}
  }
})(storage.get(KEY_USERINFO))

export function getMenu() {
  return userInfoCache && userInfoCache.menus
}

export function getToken() {
  return userInfoCache && userInfoCache.token
}

export function getUser() {
  return userInfoCache && userInfoCache.user
}

export function setUserInfo(value) {
  userInfoCache = value
  storage.set(KEY_USERINFO, value)
}

export function removeUserInfo() {
  userInfoCache = {}
  storage.remove(KEY_USERINFO)
}

